package liangtWorkSpace.base.ifElse.service;

import liangtWorkSpace.base.ifElse.action.Operation;
import liangtWorkSpace.base.ifElse.command.Command;
import liangtWorkSpace.base.ifElse.factory.OperationFactory;
import liangtWorkSpace.base.ifElse.myEnum.OperatorEnum;

/**
 * @ClassName pub
 * @Description : 测试加减乘除工厂实例
 * @Author : LiangT
 * @Date : 2020/5/14 19:05
 */
public class Calculator {
    public int calculateUsingFactory( int a, int b,String o){
        Operation operation = OperationFactory
                .getOperation(o)
                .orElseThrow(()->new IllegalArgumentException("Invalid Operation"));
        return operation.apply(a,b);
    }

    public int calculate(int a, int b, OperatorEnum operator) {
        return operator.apply(a, b);
    }


    public int calculate(Command command) {
        return command.execute();
    }
}
